<?php
class Ynbusinesspages_Model_DbTable_Business extends Engine_Db_Table {
	protected $_rowClass = 'Ynbusinesspages_Model_Business';
	
	public function getAllChildrenBusinessesByCategory($node) {
		$return_arr = array();
		$cur_arr = array();
		$list_categories = array();
		Engine_Api::_() -> getItemTable('ynbusinesspages_category') -> appendChildToTree($node, $list_categories);
		foreach ($list_categories as $category) {
			$tableCategoryMap = Engine_Api::_() -> getDbTable('categorymaps', 'ynbusinesspages');
			$select = $tableCategoryMap -> select() -> where('category_id = ?', $category -> category_id);
			$cur_arr = $tableCategoryMap -> fetchAll($select);
			if (count($cur_arr) > 0) {
				$return_arr[] = $cur_arr;
			}
		}
		return $return_arr;
	}

	public function getBusinessesByCategory($category_id) {
		$tableCategoryMap = Engine_Api::_() -> getDbTable('categorymaps', 'ynbusinesspages');
		$select = $tableCategoryMap -> select() -> where('category_id = ?', $category_id);
		return $tableCategoryMap -> fetchAll($select);
	}

}
